package cn.ahaoweb.drule.core.compile.enums;

import cn.ahaoweb.drule.core.compile.Operator;

/**
 * @Name: 条件运算符
 * @Description:
 * @Author: wangzhonghao
 * @Date: 2025/2/7 14:29
 */
public enum ConditionOperate{

    eq("==","等于", new Operator.Eq()),
    neq("!=","不等于", new Operator.Neq()),
    lt("<","小于", new Operator.Lt()),
    lte("<=","小于等于", new Operator.Lte()),
    gt(">","大于", new Operator.Gt()),
    gte(">=","大于等于", new Operator.Gte()),
    left_contains("contains","包含", "包含(左)", new Operator.LeftContains()),
    right_contains("contains","包含", "包含(右)", new Operator.RightContains()),
    not_left_contains("not contains","不包含","不包含(左)", new Operator.LeftNotContains()),
    not_right_contains("not contains","不包含", "不包含(右)", new Operator.RightNotContains()),
    in("in","存在于", new Operator.In()),
    not_in("not in","不存在于", new Operator.NotIn()),

    matches("matches","正则匹配", new Operator.Matches()),
    not_matches("not matches","正则不匹配", new Operator.NotMatches()),
    // 其他条件判断符待扩充
    ;

    // 符号
    private String symbol;

    // 中文名称
    private String chinese;

    // 描述
    private String label;

    private Operator operator;

    ConditionOperate(String symbol, String chinese, Operator operator) {
        this.symbol = symbol;
        this.chinese = chinese;
        this.label = chinese;
        this.operator = operator;
    }

    ConditionOperate(String symbol, String chinese, String label, Operator operator) {
        this.symbol = symbol;
        this.chinese = chinese;
        this.label = label;
        this.operator = operator;
    }

    public String getSymbol() {
        return symbol;
    }

    public String getChinese() {
        return chinese;
    }

    public String getLabel() {
        return label;
    }

    public Operator op() {
        return operator;
    }

    public static ConditionOperate getInstance(Class c){
        ConditionOperate[] values = ConditionOperate.values();
        for (ConditionOperate value : values) {
            if (value.op().getClass().equals(c)) {
                return value;
            }
        }
        return null;
    }

}
